package crew.blt.handsound.client.webgl.property;

import com.google.gwt.event.logical.shared.ValueChangeEvent;
import com.google.gwt.event.logical.shared.ValueChangeHandler;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.TextBox;

import crew.gwt.client.widgets.util.FloatBox;
import crew.gwt.client.widgets.util.RadioAsFloatButton;


public class PropertyFactory {

	/**
	 * Creates a property of boolean type.
	 */
	public static BooleanProperty createBooleanProperty(String propertyName){
		return new BooleanProperty(propertyName);
	}
	public static class BooleanProperty extends Property<Boolean,CheckBox> {
		
		private BooleanProperty(String propertyName) {
			super(propertyName,new CheckBox());
		}

		@Override
		public String getValueAsString() {
			return Boolean.toString(getValue());
		}

		@Override
		public void setValueByDefault(boolean fireEvent) {
			setValue(false,fireEvent);
		}
	}
	
	/**
	 * Creates a group of properties of boolean type.<br/>
	 * A exclusive property of the group could be set to true.<br/>
	 * <br/>
	 * A radio button is used for the representation.
	 */
	public static ExclusiveBooleanProperty createExclusiveBooleanProperty(String propertyName){
		return new ExclusiveBooleanProperty(propertyName);
	}
	public static class ExclusiveBooleanProperty extends Property<Float,RadioAsFloatButton> {

		public static final Float DEFAULT_VALUE = 0f;
		
		private ExclusiveBooleanProperty(String propertyName) {
			super(propertyName,new RadioAsFloatButton(propertyName));
		}
		
		@Override
		public String getValueAsString() {
			return Float.toString(getValue());
		}

		@Override
		public void setValueByDefault(boolean fireEvent) {
			setValue(DEFAULT_VALUE,fireEvent);
		}

	}

	/**
	 * Creates a property of string type.
	 */
	public static LiteralProperty createLiteralProperty(String propertyName){
		return new LiteralProperty(propertyName);
	}
	public static class LiteralProperty extends Property<String,TextBox> {
		
		private LiteralProperty(String propertyName) {
			super(propertyName,new TextBox());
			getValueWidget().setVisibleLength(4);
		}

		@Override
		public String getValueAsString() {
			return getValue();
		}

		@Override
		public void setValueByDefault(boolean fireEvent) {
			setValue("",fireEvent);
		}
	}
	

	/**
	 * Creates a property of float type.
	 */
	public static FloatProperty createFloatProperty(String propertyName){
		return new FloatProperty(propertyName);
	}
	public static class FloatProperty extends Property<Float,FloatBox> {
		
		public static final Float DEFAULT_VALUE = 0f;

		private FloatProperty(String propertyName) {
			super(propertyName, new FloatBox());
			getValueWidget().setVisibleLength(4);
		}
		
		@Override
		public String getValueAsString() {
			return Float.toString(getValue());
		}
		
		Float getFloat(){
			return Float.valueOf(getValue());
		}
		
		void setFloat(Float value){
			setValue(value,true);
		}

		@Override
		public void setValueByDefault(boolean fireEvent) {
			setValue(DEFAULT_VALUE,fireEvent);
		}
	}
}
